// const cache = new WeakMap()
const deepClone = function (a, cache = new WeakMap()) {
    if (cache.has(a)) { return cache.get(a) }
    // 不考虑 iframe
    if (a instanceof Object) {
        let result = null
        // object
        if (a instanceof Function) { // 如果a函数包括其他属性，不能100%拷贝
            // 判断a是普通函数还是箭头函数
            if (a.prototype) {
                result = function () {
                    return a.apply(this, arguments)
                }
            } else { // 箭头函数，js还包括Generator生成器函数和async异步函数
                result = (...args) => { return a.call(undefined, ...args) }
            }
        } else if (a instanceof Array) {
            result = []
        } else if (a instanceof Date) {
            result = new Date(a - 0)
        } else if (a instanceof RegExp) {
            result = new RegExp(a.source, a.flags)
        } else {
            result = {}
        }
        cache.set(a, result)
        for (let key in a) {
            if (a.hasOwnProperty(key)) {
                result[key] = deepClone(a[key], cache)
            }
        }
        return result
    } else {
        // string number bool null undefined symbol bigint
        return a
    }
}

